package xg2013.totoro.web;
import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import xg2013.totoro.domain.DesignProject;
import xg2013.totoro.domain.GraduateProject;
import xg2013.totoro.domain.ProjectToMajor;
import xg2013.totoro.domain.Student;
import xg2013.totoro.domain.StudentSelectProject;
import xg2013.totoro.domain.User;
import xg2013.totoro.service.DesignProjectService;
import xg2013.totoro.service.GetPresentUser;
import xg2013.totoro.service.PaperProjectService;
import xg2013.totoro.service.StudentSelectProjectService;
import xg2013.totoro.service.StudentService;
import xg2013.totoro.service.UserService;

@Controller

@RequestMapping("/process")
public class StudentSelectProjectController {
	@Autowired
	private StudentService studentService;
	@Autowired
	private DesignProjectService designProjectService;

	@Autowired
	private StudentSelectProjectService studentSelectProjectService;
	@Autowired
	private UserService userService;
	@RequestMapping("/studentSelectProjects")
	public String studentSelectProjects(Model model){
		User user = userService.get(GetPresentUser.presentUserId);
		Integer u_id = user.getId();
		Student student =studentService.get(u_id);
		Collection<ProjectToMajor>  projectToMajorList = student.getStudentClass().getMajor().getProjectToMajors();
		System.out.println("....................................................");
		
		model.addAttribute("projectToMajorList" , projectToMajorList);
	
		model.addAttribute("UID" , student.getId());
		return "processOfSelect/projectList";
	}
	@RequestMapping("/select")
	public String designProjectselect(Integer DP_id,Integer U_id){
		GraduateProject grauateProject = designProjectService.get(DP_id);
		Student student =studentService.get(U_id);
		StudentSelectProject studentSelectProject = new StudentSelectProject();
		studentSelectProject.setStudent(student);
		studentSelectProject.setGraduateProject(grauateProject);
		studentSelectProjectService.save(studentSelectProject);
		studentSelectProjectService.update(studentSelectProject);
		return "processOfSelect/selectSuccess";
	}
}
